<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>交个朋友-注册</title>
		<link rel="stylesheet" type="text/css" href="css/login-style.css"/>
	</head>
	<body>
		
		<!-- 注册提交输入区域 -->
		<img src="img/logo3.png" class="logo">
		<input type="text" name="" id="nickname" value="" placeholder="昵称" class="username"/>
		<input type="text" name="" id="username" value="" placeholder="用户名" class="username"/>
		<input type="password" name="" id="password" value="" placeholder="密码" class="password"/>
		<input type="password" name="" id="passwordT" value="" placeholder="确认密码" class="password"/>
		<button type="button" class="login" id="register">注册</button>
	</body>
    <script src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        //【1】处理注册事件操作
        $("#register").click(function (){
            //1.1 获取用户输入的账号和密码
            var nickname = $("#nickname").val().trim();
            var username = $("#username").val().trim();
            var password = $("#password").val().trim();
            var passwordT = $("#passwordT").val().trim();
            //1.2 两次密码是否一致
            if(password!=passwordT){
                alert("密码不一致");
                return false;
            }

            //1.3编写请求信息
            //"action":"login"  表示一个登录请求的数据提交
            var config = {
                method:"POST",
                url:"/jgpy/user",
                async:true,
                dataType:"text",
                data:{
                    "username":username,
                    "password":password,
                    "nickname":nickname,
                    "action":"register"
                },
                success:function (data){ //如果请求成功 - 回调函数 - data用于接收服务器返回的结果
                    //data : json 字符串格式
                    data = JSON.parse(data);
                    // {code:200,msg:"结果",data:""}
                    if(data.code == "200"){
                        // 注册成功后 - 处理数据
                        // alert(data.msg);
                        window.location.href = "login.html";
                    }else {
                        alert(data.msg);
                    }
                }
            }
            //1.4 开始请求
            $.ajax(config);

        });

    </script>
	
	
</html>
